#ifndef __TINYSRV_EPOLL_SELECTOR_H__
#define __TINYSRV_EPOLL_SELECTOR_H__

#include "exception.h"
#include "non_copyable.h"
#include "iselector_callback.h"

#include <sys/epoll.h>

#include <vector>


namespace tinySrv
{
  
  DECLARE_TINYSRV_EXCEPTION(EPollSelector)
  
  class EPollSelector
    : private NonCopyable
  {
  public:
    EPollSelector(int listener, int maxConnectionCount);
    ~EPollSelector();
    void AddNewSocket(int newSocket, void *data);
    void Select(unsigned long waitTimeout, ISelectorCallback *callback);
    
  private:
    int EPoll;
    typedef std::vector<epoll_event> EventPool;
    EventPool Events;
    int Listener;
    
    void CloseEPoll();
  };
  
}

#endif  // !__TINYSRV_EPOLL_SELECTOR_H__
